import UIAbility from '@ohos.app.ability.UIAbility';
import hilog from '@ohos.hilog';
import window from '@ohos.window';

export default class EntryAbility extends UIAbility {
  p = {
    name: "123", age: 22
  }
  names: Array<string> = ["1", "2"]
  ages: string[] = ["2", "23"]

  time: number = 21
  other: string = "button"
  date: any = 200

  onCreate(want, launchParam) {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onCreate');
    console.log(this.p.name, "123", "3232")
    this.ages[0]
    if (this.time > 0) {
      console.log('是空', this.p.name)
    } else {
      console.log('不是空', this.p.age)
    }

    switch (this.other) {
      case 'A': {
        console.log('不是button', this.p.name)
        break
      }
      case 'button': {
        console.log('是button', this.p.name)
        break
      }
      default: {
        console.log('错误', this.p.name)
        break
      }
    }
    for (let i = 0; i < 10; i++) {
      console.log('是button', i++)
    }
    for (const element in this.ages) {
      console.log('角标', element)
    }
    for (const element of this.ages) {
      console.log('元素', element + '22')
    }
    while (true) {

    }

    interface A {
      say()
    }

    class B implements A {
      say() {
        throw new Error('Method not implemented.');
      }
    }

    function sayhello(number): void {

    }
  }

  onDestroy() {
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onDestroy');
  }

  onWindowStageCreate(windowStage: window.WindowStage) {
    // Main window is created, set main page for this ability
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');

    windowStage.loadContent('pages/Index', (err, data) => {
      if (err.code) {
        hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
        return;
      }
      hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
    });
  }

  onWindowStageDestroy() {
    // Main window is destroyed, release UI related resources
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageDestroy');
  }

  onForeground() {
    // Ability has brought to foreground
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onForeground');
  }

  onBackground() {
    // Ability has back to background
    hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onBackground');
  }
}
